﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Baopx_API;

namespace A.Controller
{
    public class AccountController
    {
        public static void Insert(Account account)
        {
            A.M.d.Accounts.InsertOnSubmit(account);
            A.M.d.SubmitChanges();
        }

        public static void Update()
        {
            A.M.d.SubmitChanges();
        }

        public static void Delete(Account account)
        {
            A.M.d.Accounts.DeleteOnSubmit(account);
            A.M.d.SubmitChanges();
        }

        public static Account GetElementById(int id)
        {
            return A.M.d.Accounts.SingleOrDefault(i => i.Id == id);
        }

        public static List<Account> GetAll()
        {
            return A.M.d.Accounts.ToList();
        }

        public static Account Login(string userName, string password)
        {
            return
                M.d.Accounts.FirstOrDefault(
                    i => i.UserName.Equals(userName) && i.Password.Equals(password) && i.IsActive);
        }
    }
}
